<?php

if (!function_exists('get_list')) {
    /**
     * 获取数据列表
     * @param $query
     * @param null $page
     * @param null $limit
     * @return array
     */
    function get_list($query, $page=null, $limit=null){
        $has_more = false;
        $request = request();
        $page   = $page===null ? ($request->param('page') ?? 1) : $page;
        $limit  = $limit===null ? ($request->param('limit') ?? 20) : $limit;
        $page = intval($page);
        $limit = intval($limit);
        $list = $query->limit(($page - 1) * $limit, $limit + 1)->select()->toArray();
        if (count($list) > $limit) {
            $has_more = 1;
            array_pop($list);
        }
        return ['list'=>$list, 'has_more'=>$has_more, 'page'=>$page];
    }
}

if (!function_exists('rand_str')) {
    /**
     * 生成随机字符串值（加密用的）
     * @param $uri
     */
    function rand_str($length = 32){
        $str = md5(uniqid(microtime(true) . mt_rand(0,100000), true) . mt_rand(0,100000));
        while(strlen($str) < $length){
            $str .= md5(uniqid(microtime(true) . mt_rand(0,100000), true) . mt_rand(0,100000));
        };
        return substr($str, 0, $length);
    }
}


if (!function_exists('get_transport_scene_list_arr')) {
    /**
     * 获取货运种类的数组
     */
    function get_transport_scene_list_arr(){
        $transport_scene_list_arr = sysconf('transport_scene_list_arr');
        $transport_scene_list_arr = html_entity_decode($transport_scene_list_arr, ENT_QUOTES, 'UTF-8');
        $transport_scene_list_arr = json_decode($transport_scene_list_arr, true);
        return $transport_scene_list_arr;
    }
}




